# AI助手类
class AIAssistant:
    def __init__(self, id, name, type, version, online=False, score=0):
        self.id = id
        self.name = name
        self.type = type
        self.version = version
        self.online = online
        self.score = score

    def show_info(self):
        status = "在线" if self.online else "离线"
        return f"ID:{self.id} 名称:{self.name} 类型:{self.type} 版本:{self.version} 状态:{status} 评分:{self.score}"


# 管理器类
class AIManager:
    def __init__(self):
        self.assistants = []

    # 1. 显示所有助手
    def show_all(self):
        if not self.assistants:
            print("暂无AI助手")
            return

        print("\n所有AI助手：")
        for i, assistant in enumerate(self.assistants, 1):
            print(f"{i}. {assistant.show_info()}")

    # 2. 查找助手
    def find_by_id(self, id):
        for assistant in self.assistants:
            if assistant.id == id:
                return assistant
        return None

    # 3. 添加助手
    def add_assistant(self):
        print("\n添加新AI助手")
        try:
            id = int(input("请输入ID: "))
            name = input("请输入名称: ")
            type = input("请输入类型: ")
            version = input("请输入版本: ")
            online = input("是否在线(1-是,0-否): ") == "1"
            score = int(input("请输入能力评分: "))

            # 检查ID是否重复
            if self.find_by_id(id):
                print("ID已存在！")
                return

            new_assistant = AIAssistant(id, name, type, version, online, score)
            self.assistants.append(new_assistant)
            print("添加成功！")

        except:
            print("输入错误！")

    # 4. 删除助手
    def delete_assistant(self):
        try:
            id = int(input("请输入要删除的助手ID: "))
            assistant = self.find_by_id(id)

            if assistant:
                self.assistants.remove(assistant)
                print("删除成功！")
            else:
                print("未找到该助手！")

        except:
            print("输入错误！")

    # 5. 启动服务
    def start_service(self):
        try:
            id = int(input("请输入要启动的助手ID: "))
            assistant = self.find_by_id(id)

            if assistant:
                if assistant.online:
                    print("助手已在运行中")
                else:
                    assistant.online = True
                    print("启动成功！")
            else:
                print("未找到该助手！")

        except:
            print("输入错误！")

    # 6. 停止服务
    def stop_service(self):
        try:
            id = int(input("请输入要停止的助手ID: "))
            assistant = self.find_by_id(id)

            if assistant:
                if not assistant.online:
                    print("助手已停止")
                else:
                    assistant.online = False
                    print("停止成功！")
            else:
                print("未找到该助手！")

        except:
            print("输入错误！")

    # 7. 分配任务
    def assign_task(self):
        try:
            id = int(input("请输入助手ID: "))
            task = input("请输入任务内容: ")
            assistant = self.find_by_id(id)

            if assistant:
                if assistant.online:
                    print(f"✅ {assistant.name} 正在执行: {task}")
                else:
                    print(f"❌ {assistant.name} 当前离线，无法执行任务")
            else:
                print("未找到该助手！")

        except:
            print("输入错误！")

    # 8. 显示统计
    def show_stats(self):
        if not self.assistants:
            print("暂无数据")
            return

        total = len(self.assistants)
        online_count = sum(1 for a in self.assistants if a.online)
        avg_score = sum(a.score for a in self.assistants) / total

        print("\n系统统计：")
        print(f"总助手数: {total}")
        print(f"在线数量: {online_count}")
        print(f"离线数量: {total - online_count}")
        print(f"平均评分: {avg_score:.1f}")


# 主程序
def main():
    manager = AIManager()

    # 添加一些示例数据
    sample_data = [
        AIAssistant(101, "小智", "语音助手", "v1.2", True, 85),
        AIAssistant(102, "文小助", "文本助手", "v2.0", True, 92),
        AIAssistant(103, "图灵", "图像助手", "v1.5", False, 88)
    ]
    manager.assistants.extend(sample_data)

    while True:
        print("\n" + "=" * 20 + " AI助手管理器 " + "=" * 20)
        print("1. 查看所有助手")
        print("2. 添加助手")
        print("3. 删除助手")
        print("4. 启动服务")
        print("5. 停止服务")
        print("6. 分配任务")
        print("7. 系统统计")
        print("0. 退出")
        print("=" * 50)

        choice = input("请选择: ")

        if choice == "1":
            manager.show_all()
        elif choice == "2":
            manager.add_assistant()
        elif choice == "3":
            manager.delete_assistant()
        elif choice == "4":
            manager.start_service()
        elif choice == "5":
            manager.stop_service()
        elif choice == "6":
            manager.assign_task()
        elif choice == "7":
            manager.show_stats()
        elif choice == "0":
            print("再见！")
            break
        else:
            print("无效选择！")


# 启动程序
if __name__ == "__main__":
    main()